package com.ibm.spatiotemp.server.datamodel.gpsdata;

import java.util.Comparator;

import com.ibm.spatiotemp.tools.DateParser;

public class TSPoint{
	public static String tspoint_json_format = "{\"t\":\"%s\", \"p\":{\"type\":\"Point\", \"coordinates\":[%f,%f]}}";

	public String tsid;
	public double x;/*lontitue*/
	public double y;/*latitude*/
	public long time_stamp;
	
	public TSPoint(String tsid, double lon, double lat, long timestamp)
	{
		this.tsid = tsid;
		this.x = lon;
		this.y = lat;
		this.time_stamp = timestamp;
	}
	
	@Override
	public String toString() {
		return "'"+tsid +"','" + x + "','" + y + "','" + DateParser.FormatDate(time_stamp) +"'";
	}
	
	public String toJsonString()
	{
		return String.format(tspoint_json_format,
				DateParser.FormatDate(time_stamp),
				x,y);
	}
	
	public static class TSPointComparator implements Comparator {
		@Override
		public int compare(Object o1, Object o2) {
			long ts1 = ((TSPoint)o1).time_stamp;
			long ts2 = ((TSPoint)o2).time_stamp;
			return (int)(ts1-ts2);
		}
	}
}
